*This file replicates CFS's key analyses using their measure of turnout (which uses valid votes in the denominator) and my measure of turnout (which uses cast ballots in the denominator). 

cd "YOUR DIRECTORY HERE "

*************************************
*Figure 2 kernel density 
*************************************

use "CFS/Turnout_District_Level.dta", clear 


*Do once with al the data and once just with the two elections right around the reform 

*keep if year>=1918 & year<=1921

twoway (kdensity turnout if year<1920, lwidth(thick)) (kdensity turnout if year>1920 & year<1930, lwidth(thick)), title("") xtitle("") ytitle("") legend(order(1 "1909-1918" 2 "1921-1927"  ) pos(1) ring(0) col(1) off) scheme(tufte)  text(1.3 .3 "Pre-reform", size(medlarge)) text(3.2 .8 "Post", size(medlarge)) yscale(range(0 5)) ylabel(0 [1] 5) xscale(range(0 1)) xlabel(0[.1]1) 

graph export "./images/Nor_density_cox.eps", replace

*my figure: 

use "Turnout_District_Level_ladies.dta", clear 

# delimit ; 
twoway 
(kdensity turnout_CFS if year<1920, lwidth(thick) lpattern(dash) lcolor(gs6)) 
(kdensity turnout_CFS if year>1920 & year<1930, lwidth(thick) lpattern(dash) lcolor(gs6))
(kdensity turnout_DT if year<1920, lwidth(thick) lcolor(gs12) lpattern(solid) ) 
(kdensity turnout_DT if year>1920 & year<1930, lwidth(thick) lcolor(gs12) lpattern(solid))

, title("") xtitle("") ytitle("") legend(order(1 "Approved/Eligible (CFS)"  3 "Cast/Eligible" ) pos(11) ring(0) col(1) ) scheme(tufte)  text(1.3 .3 "Pre-reform", size(medlarge) ) text(3.2 .8 "Post", size(medlarge) ) yscale(range(0 5)) ylabel(0 [1] 5) xscale(range(0 1)) xlabel(0[.1]1)  ;

# delimit cr 

graph export "./images/FigA1.eps", replace

*************************************
*Figure A2 (CFS figure 3 Box and Whiskers) . 
*************************************

use "CFS/Turnout_District_Level.dta", clear 

graph box turnout, over(year) title("") ytitle("") graphregion(fcolor(white)) scheme(tufte) legend(off)

*My figure: 

use "CFS/Turnout_District_Level_ladies.dta", clear 

graph box turnout_CFS turnout_DT , over(year)  ytitle("") graphregion(fcolor(white)) scheme(tufte) legend(label (1 "CFS measure approved/eligible") label(2 "cast/eligible") row(1) )  box(1, col(gs6)) box(2, col(gs12))
graph export "./images/FigA2.eps", replace


*************************************
*Figure A3 (CFS figure 6) Quantile difference in turnout pre and post. 
*************************************


use "Turnout_District_Level_ladies.dta", clear 

drop SMD_margin_quantile
xtile SMD_margin_quantile=SMD_margin, nq(6)

foreach type in CFS DT {

bysort year SMD_margin_quantile: egen mean_turnout_`type'=mean(turnout_`type')
label var mean_turnout_`type' "Mean Voter Turnout, `type'"
}


foreach quantile in 1 2 3 4 5 6 {

# delimit ; 
twoway 
(scatter mean_turnout_CFS year if year<1920 & SMD_margin_quantile==`quantile', mstyle(p1) mcolor(gs6) msize(tiny) lstyle(p1) lpattern(dash) lcolor(gs6) connect(l)) 

(scatter mean_turnout_CFS year if year>1920 & SMD_margin_quantile==`quantile', mstyle(p1) mcolor(gs6) msize(tiny) lstyle(p1) lpattern(dash) lcolor(gs6) connect(l))

(scatter mean_turnout_DT year if year<1920 & SMD_margin_quantile==`quantile', mstyle(p1) mcolor(gs12) msize(tiny) lstyle(p1) lpattern(solid) lcolor(gs12) connect(l)) 

(scatter mean_turnout_DT year if year>1920 & SMD_margin_quantile==`quantile', mstyle(p1) mcolor(gs12) msize(tiny) lstyle(p1) lpattern(solid) lcolor(gs12) connect(l))

, 

title(Quantile `quantile') graphregion(fcolor(white)) scheme(s2mono) legend(off) ytitle("") xtitle("") xscale(range(1909 1927)) xlabel(1909[3]1927) name(DV_`quantile', replace) ; 

# delimit cr

}

graph combine DV_1  DV_2 DV_3 DV_4  DV_5  DV_6 , xcommon ycommon graphregion(fcolor(white)) scheme(tufte) row(3) col(2)

*CFS's figure 6
graph export "./images/FigA3.eps", replace


*************************************
*Table 2 
*************************************

use "Turnout_District_Level_ladies.dta", clear 

sort year PR_district
capture drop _merge
merge m:1 year PR_district using "CFS/AlternativeMargin.dta"
drop if _merge==2 /* PR-districts not in sample */

gen d2127=0
replace d2127=1 if year==1921|year==1924|year==1927

egen avgC1=mean(C1), by(PR_district d2127)
egen avgC2=mean(C2), by(PR_district d2127)
egen avgmin_distance=mean(min_distance), by(PR_district d2127)
egen avgmin_distance1=mean(min_distance1), by(PR_district d2127)
egen avgmin_distance_iXv_i=mean(min_distance_iXv_i), by(PR_district d2127)
egen avgmin_distance1_iXv_i=mean(min_distance1_iXv_i), by(PR_district d2127)

gen Margin=SMD_margin_pre
gen Margin2=SMD_margin_pre^2

tab PR_district, gen(d_PR_district)

gen ch_margin=avgmin_distance1-Margin

/* third lag turnout
gen ch_turnout_CFS=turnout_CFS-l3.turnout_CFS 
gen ch_turnout_DT=turnout_DT-l3.turnout_DT
*/ 
*** Analysis with heteroscedasticity-robust standard errors

eststo clear
reg ch_turnout_CFS Margin if year==1921, robust
eststo
reg ch_turnout_DT Margin if year==1921, robust
eststo

reg ch_turnout_CFS Margin Margin2 if year==1921, robust
eststo
reg ch_turnout_DT Margin Margin2 if year==1921, robust
eststo

reg ch_turnout_CFS Margin avgmin_distance1 if year==1921, robust
eststo
reg ch_turnout_DT Margin avgmin_distance1 if year==1921, robust
eststo

reg ch_turnout_CFS ch_margin if year==1921, robust
eststo
reg ch_turnout_DT ch_margin if year==1921, robust
eststo

reg ch_turnout_CFS Margin d_PR_* if year==1921, robust nocons
eststo
reg ch_turnout_DT Margin d_PR_* if year==1921, robust nocons
eststo

esttab using "./tables/Table2_robustSE.tex", replace cells(b(fmt(3)) se(par fmt(3))) r2 nostar  drop(d_PR*) nodepvars mtitles("CFS" "New" "CFS" "New" "CFS" "New" "CFS" "New" "CFS" "New") label



*************************************
*Figure 7 
*************************************

use "Turnout_District_Level_ladies.dta", clear 

**Trying to put all three on one graph together

# delimit ;
twoway 


(lfitci ch_turnout_CFS SMD_margin_pre if year==1921,   lcolor(gs6) lpattern(solid) estopts(cluster(PR_district))) 

(lfitci ch_turnout_DT SMD_margin_pre if year==1921,   estopts(cluster(PR_district)) lpattern(dash) lcolor(gs12))
 (scatter ch_turnout_DT SMD_margin_pre if year==1921, mstyle(p1) mcolor(gs12) msymbol(+) )

(scatter ch_turnout_CFS SMD_margin_pre if year==1921, mstyle(p1) mcolor(gs6) msymbol(Oh) ) 

, 
title("") ytitle("Change in turnout 1918-1921") xtitle(Average first round margin 1909-1918) legend(order( 3 "approved/eligible, CFS measure" 6 "cast/eligible") row(1) ) graphregion(fcolor(white)) scheme(tufte) ;

# delimit cr 

graph export "./images/FigA4.eps", replace






